package com.hc.pingtan.controller;


import com.alibaba.fastjson.TypeReference;
import com.hc.pingtan.conf.ImageReplace;
import com.hc.pingtan.model.CommonResult;
import com.hc.pingtan.model.SxoOrder;
import com.hc.pingtan.model.SxoUserOrderVo;
import com.hc.pingtan.service.ISxoOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 订单 前端控制器
 * </p>
 *
 * @author astupidcoder
 * @since 2021-11-02
 */
@Api(tags = "订单")
@RestController
@RequestMapping("/sxo-order")
public class SxoOrderController {

    @Autowired
    private ISxoOrderService mISxoOrderService;
    @Autowired
    private ImageReplace imageReplace;

    /**
     * @return
     */
    @ApiImplicitParams({@ApiImplicitParam(name = "type", value = "订单状态（0待确认, 1已确认/待支付, 2已支付/待发货, 3已发货/待收货, 4已完成, 5已取消, 6已关闭）"), @ApiImplicitParam(name = "title", value = "标题搜索")})
    @ApiOperation(value = "我的订单列表", notes = "我的订单列表", httpMethod = "GET")
    @GetMapping("/findSxoUserOrderList")
    public CommonResult<List<SxoUserOrderVo>> findSxoUserOrderVo(String type, String title) {
        CommonResult<List<SxoUserOrderVo>> result = CommonResult.<List<SxoUserOrderVo>>builder().build();
        List<SxoUserOrderVo> list = mISxoOrderService.findSxoUserOrderVo(type, title);
        result.setResult(imageReplace.shopxoImageReplace(list, new TypeReference<List<SxoUserOrderVo>>() {
        }));
        return result;
    }

    /**
     * 取消订单
     *
     * @return
     */
    @ApiImplicitParam(name = "id", value = "订单ID")
    @ApiOperation(value = "取消订单", notes = "取消订单", httpMethod = "GET")
    @GetMapping("/cancelOrder")
    public CommonResult cancelOrder(Integer id) {
        SxoOrder sxoOrder = new SxoOrder();
        sxoOrder.setStatus(5);//取消订单
        sxoOrder.setId(id);
        mISxoOrderService.updateById(sxoOrder);
        return CommonResult.builder().build();
    }

    /**
     * 取消订单
     *
     * @return
     */
    @ApiImplicitParam(name = "id", value = "订单ID")
    @ApiOperation(value = "确认订单", notes = "确认订单", httpMethod = "GET")
    @GetMapping("/confirmOrder")
    public CommonResult confirmOrder(Integer id) {
        SxoOrder sxoOrder = new SxoOrder();
        sxoOrder.setStatus(4);//确认收货
        sxoOrder.setId(id);
        mISxoOrderService.updateById(sxoOrder);
        return CommonResult.builder().build();
    }

}
